package rest.home.ui;

import rest.home.conntroller.RestHomeController;
import rest.home.entity.*;
import rest.home.entity.ms.Limit;
import rest.home.entity.ms.OlderAndVisitorAndRoom;


import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Scanner;

/**
 * @author: lbc
 * @Date: 2022/5/5 15:17
 * @version: 8.0
 * @describe:
 */
public class REstHome {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        RestHomeController rsco = new RestHomeController();
        System.out.println("-----欢迎来到养老院管理系统-----");
        System.out.println("请输入登录账号");
        String adminId=sc.next();
        System.out.println("请输入密码");
        String passWord=sc.next();
        boolean login = rsco.login(adminId, passWord);
        if (login){
            boolean flag=true;
            while (flag){
                System.out.println("------------养老院管理系统------------");
                System.out.println("1、账号管理");
                System.out.println("2、老人信息管理");
                System.out.println("3、入住管理");
                System.out.println("4、健康管理");
                System.out.println("5、安全管理");
                System.out.println("6、收费管理");
                System.out.println("7、护理人员信息管理");
                System.out.println("8、外出管理");
                System.out.println("请输入你的选择");
                int key = sc.nextInt();
                switch (key){
                    case 1:
                        System.out.println("------------账号管理------------");
                        System.out.println("1、已有账号的查询");
                        System.out.println("2、新增账号");
                        System.out.println("请输入你的选择");
                        int key1 = sc.nextInt();
                        switch (key1){
                            case 1:
                                List<Admin> allAdmin11 = rsco.findAllAdmin();
                                for (Admin admin11 : allAdmin11) {
                                    System.out.println(admin11);
                                }
                                break;
                            case 2:
                                Admin admin = new Admin();
                                System.out.println("请输入新增账号");
                                admin.setAdminId(sc.next());
                                System.out.println("请输入新增密码");
                                admin.setPassWord(sc.next());
                                List<Admin> allAdmin12 = rsco.findAllAdmin();
                                Integer i12=0;
                                for (Admin admin12 : allAdmin12) {
                                    if (admin12.getAdminId().equals(admin.getAdminId())){
                                        i12=1;
                                        break;
                                    }
                                }
                                if (i12==1){
                                    System.out.println("账号已存在");
                                    break;
                                }
                                if (i12==0){
                                    Boolean addAdmin = rsco.addAdmin(admin);
                                    System.out.println(addAdmin?"添加成功":"添加失败");
                                    break;
                                }
                                break;
                        }
                        break;
                    case 2:
                        System.out.println("------------老人信息管理------------");
                        System.out.println("1、查询老人信息");
                        System.out.println("2、修改老人信息");
                        System.out.println("3、添加老人信息");
                        System.out.println("4、删除老人信息");
                        System.out.println("请输入你的选择");
                        int key2 = sc.nextInt();
                        switch (key2){
                            case 1:
                                List<Older> list21 = rsco.findAll();
                                for (Older older21 : list21) {
                                    System.out.println(older21);
                                }
                                break;
                            case 2:
                                System.out.println("请输入修改老人ID编号");
                                Integer olderId=sc.nextInt();
                                Older olderIdByOlder = rsco.findOlderIdByOlder(olderId);
                                SimpleDateFormat sdf22 = new SimpleDateFormat("yyyy-MM-dd");
                                if (olderIdByOlder.getOlderId()!=null){
                                    System.out.println("老人原姓名为："+olderIdByOlder.getOlderName()+"请输入老人新的姓名(输入0表示不输入):");
                                    String updateOlderName=sc.next();
                                    if (!"0".equals(updateOlderName)){
                                        olderIdByOlder.setOlderName(updateOlderName);
                                    }
                                    System.out.println("老人原性别为："+olderIdByOlder.getOlderGender()+"请输入老人新的性别(输入0表示不输入):");
                                    String updateOlderGender=sc.next();
                                    if (!"0".equals(updateOlderGender)){
                                        olderIdByOlder.setOlderGender(updateOlderGender);
                                    }
                                    System.out.println("老人原电话号为："+olderIdByOlder.getOlderPhone()+"请输入老人新的电话号码(输入0表示不输入):");
                                    Long updateOlderPhone=sc.nextLong();
                                    if (updateOlderPhone!=0){
                                        olderIdByOlder.setOlderPhone(updateOlderPhone);
                                    }
                                    System.out.println("老人原住址为："+olderIdByOlder.getOlderAddress()+"请输入老人新的住址(输入0表示不输入):");
                                    String updateOlderAddress=sc.next();
                                    if (!"0".equals(updateOlderAddress)){
                                        olderIdByOlder.setOlderAddress(updateOlderAddress);
                                    }
                                    System.out.println("老人原身体状态等级为："+olderIdByOlder.getHealth()+"请输入老人新的身体状态等级(输入0表示不输入):");
                                    Integer updateHealth=sc.nextInt();
                                    if (updateHealth!=0){
                                        olderIdByOlder.setHealth(updateHealth);
                                    }
                                    System.out.println("老人原入住时间为："+olderIdByOlder.getCheckinDate()+"是否更改入住时间(输入0表示不更改)");
                                    String updateCheckinDate=sc.next();
                                    if (!"0".equals(updateCheckinDate)){
                                        Date date22=null;
                                        try {
                                            date22 = sdf22.parse(updateCheckinDate);
                                        } catch (ParseException e) {
                                            e.printStackTrace();
                                        }
                                        olderIdByOlder.setCheckinDate(date22);
                                    }
                                    System.out.println("老人原房间为："+olderIdByOlder.getRoomId()+"是否更换房间(输入0表示不更换)");
                                    Integer updateRoomId=sc.nextInt();
                                    if (updateRoomId!=0){
                                        List<Room> rooms = rsco.showRoom();
                                        System.out.println("可选房间如下：");
                                        for (Room room : rooms) {
                                            System.out.println(room.getRoomId());
                                        }
                                        olderIdByOlder.setRoomId(sc.nextInt());
                                    }
                                    System.out.println("老人原护工为："+olderIdByOlder.getNurseId()+"是否更换护工(输入0表示不更换)");
                                    Integer updateNurseId=sc.nextInt();
                                    if (updateNurseId!=0){
                                        List<Nurse> allNurse = rsco.findAllNurse();
                                        System.out.println("可选护工如下：");
                                        for (Nurse nurse22 : allNurse) {
                                            System.out.println(nurse22.getNurseId());
                                        }
                                        olderIdByOlder.setNurseId(sc.nextInt());
                                    }
                                    Integer integer = rsco.updateOlder(olderIdByOlder);
                                    if (integer!=null||integer!=0){
                                        System.out.println("修改成功");
                                    }else {
                                        System.out.println("修改失败");
                                    }
                                }else {
                                    System.out.println("此编号不存在");
                                }
                                break;
                            case 3:
                                Older older23 = new Older();
                                System.out.println("请输入新入住的老人姓名:");
                                older23.setOlderName(sc.next());
                                System.out.println("请输入新入住的老人性别:");
                                older23.setOlderGender(sc.next());
                                System.out.println("请输入新入住的老人的手机号:");
                                older23.setOlderPhone(sc.nextLong());
                                System.out.println("请输入新入住的老人的家庭住址：");
                                older23.setOlderAddress(sc.next());
                                System.out.println("请输入新入住的老人的身体健康等级如下：");
                                System.out.println("轻症（ 0 ）");
                                System.out.println("中期（ 1 ）");
                                System.out.println("重症（ 2 ）");
                                older23.setHealth(sc.nextInt());
                                System.out.println("请输入新入住的老人的入住时间");
                                String addOlderDate=sc.next();
                                if (!"0".equals(addOlderDate)){
                                    SimpleDateFormat sdf23 = new SimpleDateFormat("yyyy-MM-dd");
                                    Date addOlderAddress=null;
                                    try {
                                        addOlderAddress = sdf23.parse(addOlderDate);
                                    } catch (ParseException e) {
                                        e.printStackTrace();
                                    }
                                    older23.setCheckinDate(addOlderAddress);
                                }
                                List<Room> rooms = rsco.showRoom();
                                System.out.println("剩余房间如下：");
                                for (Room room23 : rooms) {
                                    System.out.println(room23.getRoomId());
                                }
                                System.out.println("请输入新入住的老人的入住房间");
                                older23.setRoomId(sc.nextInt());
                                List<Nurse> allNurse = rsco.findAllNurse();
                                System.out.println("本院可选护工如下：");
                                for (Nurse nurse23 : allNurse) {
                                    System.out.println(nurse23.getNurseId()+":"+nurse23.getNurseName());
                                }
                                older23.setNurseId(sc.nextInt());
                                Boolean addOlder = rsco.addOlder(older23);
                                System.out.println(addOlder?"添加成功":"添加失败");
                                break;
                            case 4:
                                System.out.println("请输入需要删除的老人ID");
                                Integer deleteOlderId=sc.nextInt();
                                Boolean deleteOlder = rsco.deleteOlder(deleteOlderId);
                                if (deleteOlder){
                                    System.out.println("删除成功");
                                }else {
                                    System.out.println("删除失败");
                                }
                                break;
                            default:
                                System.out.println("暂无此选择");
                                break;
                        }
                        break;
                    case 3:
                        System.out.println("------------入住管理------------");
                        while (true){
                            System.out.println("1、展示的房间信息");
                            System.out.println("2、添加一个房间信息");
                            System.out.println("3、修改一个房间信息");
                            System.out.println("4、删除一个房间信息");
                            System.out.println("请输入你的选择");
                            int key3 = sc.nextInt();
                            switch (key3){
                                case 1:
                                    System.out.println("所有的房间信息如下:");
                                    List<Room> rooms = rsco.showRoom();
                                    for (Room room : rooms) {
                                        System.out.println(room);
                                    }
                                    break;
                                case 2:
                                    Room addRoom = new Room();
                                    System.out.println("请输入您要添加的房间号:");
                                    Integer addRoomId = sc.nextInt();
                                    Boolean addFlag=false;
                                    List<Room> rooms21 = rsco.showRoom();
                                    for (Room room : rooms21) {
                                        if (!room.equals(addRoomId)){
                                            addRoom.setRoomId(addRoomId);
                                            addFlag=true;
                                        }
                                    }
                                    if (addFlag){
                                        System.out.println("可选择的房间类型如下:");
                                        System.out.println("双人间");
                                        System.out.println("单人间");
                                        System.out.println("请输入房间的类型:(输入0代表不输入)");
                                        String addRoomName = sc.next();
                                        if (!addFlag.equals("0")){
                                            addRoom.setRoomType(addRoomName);
                                        }
                                        addRoom.setRoomType("单人间");
                                        addRoom.setRoomStatus(0);
                                        Integer integer = rsco.addRoomMessage(addRoom);
                                        if (integer!=null||integer!=0){
                                            System.out.println("添加成功");
                                        }else {
                                            System.out.println("添加失败");
                                        }
                                    }else {
                                        System.out.println("您输入的房间号已存在，请重新输入");
                                    }
                                    break;
                                case 3:
                                    System.out.println("请输入您要修改的房间编号:");
                                    System.out.println("可选择的房间如下:");
                                    //展示所有可用的房间
                                    List<Room> rooms1 = rsco.showRoomByStatus();
                                    for (Room room : rooms1) {
                                        System.out.println(room);
                                    }
                                    Room updateRoom = new Room();
                                    System.out.println("可选择的房间类型如下");
                                    System.out.println("双人间");
                                    System.out.println("单人间");
                                    System.out.println("请选择您的房间类型");
                                    String addRoomType = sc.next();
                                    updateRoom.setRoomType(addRoomType);
                                    List<Room> rooms4 = rsco.showRoomByType(addRoomType);
                                    for (Room room : rooms4) {
                                        System.out.println(room);
                                    }
                                    System.out.println("请输入您要选择的房间编号:");
                                    Integer addId = sc.nextInt();
                                    updateRoom.setId(addId);
                                    for (Room room : rooms4) {
                                        if (room.getId().equals(addId)&&room.getRoomStatus()==0
                                                &&room.getRoomType().equals("单人间")){
                                            updateRoom.setRoomStatus(2);
                                            updateRoom.setRoomId(room.getRoomId());
                                        }else if (room.getId().equals(addId)&&room.getRoomStatus()==0
                                                &&room.getRoomType().equals("双人间")){
                                            updateRoom.setRoomStatus(1);
                                            updateRoom.setRoomId(room.getRoomId());
                                        }else if (room.getId().equals(addId)&&room.getRoomStatus()==1
                                                &&room.getRoomType().equals("双人间")){
                                            updateRoom.setRoomStatus(2);
                                            updateRoom.setRoomId(room.getRoomId());
                                        }
                                    }
                                    Integer roomMessage = rsco.updateRoomMessage(updateRoom);
                                    if (roomMessage!=null||roomMessage!=0){
                                        System.out.println("修改成功");
                                    }else {
                                        System.out.println("修改失败");
                                    }
                                    break;
                                case 4:
                                    System.out.println("请输入您要删除的房间编号:");
                                    Integer deleteId = sc.nextInt();
                                    List<Room> rooms41 = rsco.showRoom();
                                    boolean deleteFlag=false;
                                    for (Room room : rooms41) {
                                        if (room.getId().equals(deleteId)) {
                                            deleteFlag = true;
                                        }
                                    }
                                    if (deleteFlag){
                                        Boolean aBoolean = rsco.deleteRoomMessage(deleteId);
                                        if (aBoolean){
                                            System.out.println("删除成功");
                                        }else {
                                            System.out.println("删除失败");
                                        }
                                    }else {
                                        System.out.println("您输入的房间编号不存在");
                                    }
                                    break;
                            }
                            System.out.println("是否继续入住信息的操作(Y/N)");
                            String nexts = sc.next();
                            if (nexts.equalsIgnoreCase("N")){
                                break;
                            }
                        }
                        break;
                    case 4:
                        while (true){
                            System.out.println("------------健康管理------------");
                            System.out.println("1、健康信息查询");
                            System.out.println("2、健康信息修改");
                            System.out.println("3、药品信息查询");
                            System.out.println("4、药品信息新增");
                            System.out.println("5、药品信息修改");
                            System.out.println("6、药品信息删除");
                            System.out.println("7、添加健康信息");
                            System.out.println("请输入你的选择");
                            int key41 = sc.nextInt();
                            switch (key41){
                                case 1:
                                    System.out.println("所有的健康信息如下:");
                                    List<Health> health = rsco.showHealthByType();
                                    for (Health health1 : health) {
                                        System.out.println(health1);
                                    }
                                    break;
                                case 2:
                                    Health updateHealth = new Health();
                                    System.out.println("请输入您要修改的老人编号:");
                                    Integer updateOlderId = sc.nextInt();
                                    List<Health> health1 = rsco.showHealthByType();
                                    Boolean healthFlag=false;
                                    Integer updateOlderStr=null;
                                    String updateOlderStatus=null;
                                    Integer updateOlderIdOld=null;
                                    for (Health health12 : health1) {
                                        if (updateOlderId.equals(health12.getOlderId())){
                                            updateHealth.setOlderId(health12.getOlderId());
                                            updateOlderStr=health12.getHealth();
                                            updateOlderStatus=health12.getDisease();
                                            updateOlderIdOld=health12.getMedicineId();
                                            healthFlag=true;
                                            break;
                                        }
                                    }
                                    if (healthFlag){
                                        System.out.println("可选则的状态如下:");
                                        System.out.println("0------代表良好");
                                        System.out.println("1------代表较差");
                                        System.out.println("2------代表很差");
                                        System.out.println("老人原来的状态为:"+updateOlderStr+"请输入老人的健康状态:");
                                        updateHealth.setHealth(sc.nextInt());
                                        System.out.println("老人原来所患的疾病为:"+updateOlderStatus+"请输入老人所患的疾病:");
                                        updateHealth.setDisease(sc.next());
                                        System.out.println("老人原来所患的疾病为:"+updateOlderIdOld+"请输入老人所用药瓶的编号:");
                                        updateHealth.setMedicineId(sc.nextInt());
                                        Boolean aBooleans = rsco.updateHealthMessage(updateHealth);
                                        if (aBooleans){
                                            System.out.println("修改成功");
                                        }else {
                                            System.out.println("修改失败");
                                        }
                                    }
                                    break;
                                case 3:
                                    System.out.println("所有的药品信息如下:");
                                    List<Medicine> medicines = rsco.showMedicine();
                                    for (Medicine medicine : medicines) {
                                        System.out.println(medicine);
                                    }
                                    break;
                                case 4:
                                    Medicine addMedicine = new Medicine();
                                    System.out.println("请输入新增药品的名称:");
                                    addMedicine.setMedicineName(sc.next());
                                    System.out.println("请输入药品的价格:");
                                    addMedicine.setMedicinePrice(sc.nextInt());
                                    Boolean medicineFlag = rsco.addMedicine(addMedicine);
                                    if (medicineFlag){
                                        System.out.println("添加成功");
                                    }else {
                                        System.out.println("添加失败");
                                    }
                                    break;
                                case 5:
                                    Medicine updateMedicine = new Medicine();
                                    System.out.println("请输入您要修改的药品编号:");
                                    Integer updateId = sc.nextInt();
                                    List<Medicine> medicines5 = rsco.showMedicine();
                                    Boolean updateFlag=false;
                                    String updateMedicineStr=null;
                                    Integer updateMedicinePrice=null;
                                    for (Medicine medicine : medicines5) {
                                        if (updateId.equals(medicine.getMedicineId())){
                                            updateMedicine.setMedicineId(medicine.getMedicineId());
                                            updateMedicineStr=medicine.getMedicineName();
                                            updateMedicinePrice=medicine.getMedicinePrice();
                                            updateFlag=true;
                                            break;
                                        }
                                    }
                                    if (updateFlag){
                                        System.out.println("原药品名为:"+updateMedicineStr+"; 请输入药品的名称:");
                                        updateMedicine.setMedicineName(sc.next());
                                        System.out.println("原药品价格为:"+updateMedicinePrice+"$; 请输入药品的价格:");
                                        updateMedicine.setMedicinePrice(sc.nextInt());
                                        Boolean updateMedicineFlag = rsco.updateMedicine(updateMedicine);
                                        if (updateMedicineFlag){
                                            System.out.println("修改成功");
                                        }else {
                                            System.out.println("修改失败");
                                        }
                                    }else{
                                        System.out.println("此药品不存在!!!");
                                    }
                                    break;
                                case 6:
                                    System.out.println("请输入要删除药品的编号");
                                    Integer deleteMedicine = sc.nextInt();
                                    Boolean deleteMedicineFlag=false;
                                    List<Medicine> medicines2 = rsco.showMedicine();
                                    for (Medicine medicine : medicines2) {
                                        if (medicine.getMedicineId().equals(deleteMedicine)){
                                            System.out.println(deleteMedicine);
                                            deleteMedicineFlag=true;
                                            break;
                                        }
                                    }
                                    if (deleteMedicineFlag){
                                        Boolean aBoolean = rsco.deleteMedicine(deleteMedicine);
                                        if (aBoolean){
                                            System.out.println("删除成功");
                                        }else {
                                            System.out.println("删除失败");
                                        }
                                    }else {
                                        System.out.println("您输入的药品编号不存在!!!");
                                    }
                                    break;
                                case 7:
                                    //添加健康信息
                                    Health addHealth = new Health();
                                    System.out.println("请输入老人的编号:");
                                    addHealth.setOlderId(sc.nextInt());
                                    System.out.println("老人的状态可选择的如下:");
                                    System.out.println("0----------良好");
                                    System.out.println("1----------较差");
                                    System.out.println("2----------很差");
                                    System.out.println("请输入您要添加的老人状态:");
                                    addHealth.setHealth(sc.nextInt());
                                    System.out.println("请输入老人所患的疾病:");
                                    addHealth.setDisease(sc.next());
                                    System.out.println("请输入老人所用药物的编号");
                                    addHealth.setMedicineId(sc.nextInt());
                                    Boolean aBoolean = rsco.addHealth(addHealth);
                                    if (aBoolean){
                                        System.out.println("添加成功");
                                    }else {
                                        System.out.println("添加失败");
                                    }
                                    break;

                                default:
                                    System.out.println("您输入的代码有误,请重新输入");
                                    break;
                            }
                            System.out.println("是否继续健康信息的操作(Y/N)");
                            String nexts = sc.next();
                            if (nexts.equalsIgnoreCase("N")){
                                break;
                            }
                        }
                        break;
                    case 5:
                        System.out.println("------------安全管理------------");
                        System.out.println("1.事故信息管理");
                        System.out.println("2.访客信息管理");
                        int i = sc.nextInt();
                        switch (i) {
                            case 1:
                                System.out.println("事故信息管理");
                                System.out.println("1.事故信息查询");
                                System.out.println("2.事故信息修改");
                                System.out.println("3.事故信息新增");
                                System.out.println("4.事故信息删除");
                                int tb = sc.nextInt();
                                switch (tb) {
                                    case 1:
                                        System.out.println("事故信息查询");
                                        List<Trouble> list = rsco.findAllTrouble();
                                        for (Trouble trouble : list) {
                                            System.out.println(trouble);
                                        }
                                        break;
                                    case 2:
                                        System.out.println("请输入要修改的事故信息编号");
                                        int troubleid = sc.nextInt();
                                        Trouble trouble = rsco.findTroubleById(troubleid);
                                        if (trouble.getTroubleId() != null) {
                                            System.out.println("原事故时间为：" + trouble.getTroubleDate() + "请输入新的事故发生时间(输入0表示不输入)：");
                                            String updateDate = sc.next();
                                            if (!"0".equals(updateDate)) {
                                                Date parse = null;
                                                try {
                                                    parse = sdf.parse(updateDate);
                                                } catch (ParseException e) {
                                                    e.printStackTrace();
                                                }
                                                trouble.setTroubleDate(parse);
                                            }
                                            System.out.println("原事故信息为：" + trouble.getTroubleMessage() + "请输入新的事故详细信息(输入0表示不输入)");
                                            String updateMessage = sc.next();
                                            if (!"0".equals(updateMessage)) {
                                                trouble.setTroubleMessage(updateMessage);
                                            }
                                            System.out.println("可选择的状态如下:");
                                            System.out.println("0.------已解决");
                                            System.out.println("1.------未解决");
                                            System.out.println("请输入事故状态对应的编号:");
                                            Integer statusId = sc.nextInt();
                                            if (0 != statusId) {
                                                trouble.setTroubleStatus(statusId);
                                            }
                                            Integer integer = rsco.updateTroubleById(trouble);
                                            if (integer != null) {
                                                System.out.println("修改成功");
                                            } else {
                                                System.out.println("修改失败");
                                            }
                                        }
                                        break;
                                    case 3:
                                        Trouble addTb = new Trouble();
                                        System.out.println("事故信息新增");
                                        System.out.println("请输入新增事故的日期");
                                        String addDate = sc.next();
                                        Date parse = null;
                                        try {
                                            parse = sdf.parse(addDate);
                                        } catch (ParseException e) {
                                            e.printStackTrace();
                                        }
                                        addTb.setTroubleDate(parse);
                                        System.out.println("请输入新增事故的描述");
                                        addTb.setTroubleMessage(sc.next());
                                        System.out.println("可选择的状态如下:");
                                        System.out.println("0.------已解决");
                                        System.out.println("1.------未解决");
                                        System.out.println("请输入事故状态对应的编号:");
                                        Integer statusId = sc.nextInt();
                                        if (0 != statusId) {
                                            addTb.setTroubleStatus(statusId);
                                        }
                                        Boolean integer = rsco.addTrouble(addTb);
                                        if (integer != null) {
                                            System.out.println("添加成功");
                                        } else {
                                            System.out.println("添加失败");
                                        }
                                        break;
                                    case 4:
                                        System.out.println("事故信息删除");
                                        System.out.println("请输入要删除的事故信息编号");
                                        int deleteId = sc.nextInt();
                                        Boolean deleteTb = rsco.deleteTrouble(deleteId);
                                        if (deleteTb) {
                                            System.out.println("删除成功");
                                        } else {
                                            System.out.println("删除失败");
                                        }
                                        break;
                                    default:
                                        System.out.println("输入有误！");
                                        break;
                                }
                                break;
                            case 2:
                                System.out.println("访客信息管理");
                                System.out.println("1.访客信息的展示");
                                System.out.println("2.访客信息的修改");
                                System.out.println("3.访客信息的新增");
                                System.out.println("4.访客信息的删除");
                                System.out.println("5.分页展示访客信息及老人信息及房间号");
                                int vt = sc.nextInt();
                                switch (vt) {
                                    case 1:
                                        System.out.println("访客信息的展示");
                                        List<Visitor> visitors = rsco.showAllVisitor();
                                        for (Visitor visitor : visitors) {
                                            System.out.println(visitor);
                                        }
                                        break;
                                    case 2:
                                        System.out.println("访客信息的修改");
                                        System.out.println("请输入要修改的访客信息编号");
                                        int vsId=sc.nextInt();
                                        Visitor vistorById = rsco.findVistorById(vsId);
                                        if (vistorById.getVisitorId()!=null){
                                            System.out.println("原访客姓名为：" + vistorById.getVisitorName() + "请输入新的访客姓名(输入0表示不输入)");
                                            String updateName = sc.next();
                                            if (!"0".equals(updateName)) {
                                                vistorById.setVisitorName(updateName);
                                            }
                                            System.out.println("原访客日期为："+vistorById.getVisitorDate()+"请输入新的访客日期(输入0表示不输入)");
                                            String updateDate = sc.next();
                                            if (!"0".equals(updateDate)){
                                            Date parse =null;
                                            try {
                                                parse = sdf.parse(updateDate);
                                            } catch (ParseException e) {
                                                e.printStackTrace();
                                            }
                                            vistorById.setVisitorDate(parse);
                                            }
                                            System.out.println("原访客电话号为："+vistorById.getVisitorPhone()+"请输入新的访客电话(输入0表示不输入)");
                                            Long updatePhone=sc.nextLong();
                                            if (!"0".equals(updatePhone)){
                                                vistorById.setVisitorPhone(updatePhone);
                                            }
                                            Boolean updateFalg = rsco.updateVisitore(vistorById);
                                            if (updateFalg!=null){
                                                System.out.println("修改成功");
                                            }else {
                                                System.out.println("修改失败");
                                            }
                                        }else {
                                            System.out.println("不存在此人");
                                        }
                                        break;
                                    case 3:
                                        System.out.println("访客信息的新增");
                                        Visitor addVs = new Visitor();
                                        System.out.println("请输入新进访客人员姓名");
                                        addVs.setVisitorName(sc.next());
                                        System.out.println("请输入新进访客人员的日期");
                                        String addDate=sc.next();
                                        Date parse =null;
                                        try {
                                            parse = sdf.parse(addDate);
                                        } catch (ParseException e) {
                                            e.printStackTrace();
                                        }
                                        addVs.setVisitorDate(parse);
                                        System.out.println("请输入新进访客人员的电话号码");
                                        addVs.setVisitorPhone(sc.nextLong());
                                        System.out.println("请输入访问的老人编号");
                                        addVs.setOlderId(sc.nextInt());
                                        Boolean addFlag = rsco.addVisitor(addVs);
                                        if (addFlag){
                                            System.out.println("新增成功");
                                        }else {
                                            System.out.println("新增失败");
                                        }
                                        break;
                                    case 4:
                                        System.out.println("访客信息的删除");
                                        System.out.println("请输入要删除的访客信息编号");
                                        int deleteId = sc.nextInt();
                                        Boolean deleteVs = rsco.deleteVisitor(deleteId);
                                        if (deleteVs) {
                                            System.out.println("删除成功");
                                        } else {
                                            System.out.println("删除失败");
                                        }
                                        break;
                                    case 5:
                                        System.out.println("分页展示访客访问信息");
                                        Limit<OlderAndVisitorAndRoom> limit = rsco.OlderAndVisitorAndRoomByPage(0);
                                        List list = limit.getList();
                                        for (Object o : list) {
                                            OlderAndVisitorAndRoom oVR=(OlderAndVisitorAndRoom) o;
                                            System.out.println(oVR);
                                        }
                                        System.out.println("总数据量为:" + limit.getOlderNums() + ";总条数为:" + limit.getOlderPage());
                                        while (true){
                                            System.out.println("请输入要看的页数");
                                            Integer i2=sc.nextInt();
                                            if (i2<=limit.getOlderPage()&& i2 > 0){
                                                Limit<OlderAndVisitorAndRoom> limit2 = rsco.OlderAndVisitorAndRoomByPage(i2);
                                                List<OlderAndVisitorAndRoom> list2 = limit2.getList();
                                                for (OlderAndVisitorAndRoom AV : list2) {
                                                    OlderAndVisitorAndRoom oVR=(OlderAndVisitorAndRoom) AV;
                                                    System.out.println(oVR);
                                                }
                                                System.out.println("当前页为第："+i2+"页"+"总数据量为："+ limit2.getOlderNums()+";总条数为:"+limit2.getOlderPage());
                                                if (i2>3){
                                                    break;
                                                }
                                            }else {
                                                System.out.println("输入有误");
                                            }
                                            System.out.println("是否要继续访客的信息的操作(Y/N)");
                                            String flagVistor = sc.next();
                                            if (flagVistor.equalsIgnoreCase("N")){
                                                break;
                                            }
                                        }
                                        break;
                                    default:
                                        System.out.println("输入有误！");
                                        break;
                                }
                                break;
                        }
                        break;
                    default:
                        System.out.println("输入有误!!!");
                    case 6:
                        System.out.println("------------收费管理------------");
                        System.out.println("1、入住费用查询");
                        System.out.println("2、护理费用查询");
                        System.out.println("3. 查询缴费状态");
                        System.out.println("请输入你的选择");
                        int key6 = sc.nextInt();
                        switch (key6) {
                            case 1:
                                List<PayMent> allPayMent = rsco.findAllPayMent();
                                for (PayMent payMent : allPayMent) {
                                    System.out.println(payMent);
                                }
                                break;
                            case 2:
                                List<NursingPayMent> nursingPayMents = rsco.showAllNursing();
                                for (NursingPayMent nursingPayMent : nursingPayMents) {
                                    System.out.println(nursingPayMent);
                                }
                                break;
                            case 3:
                                System.out.println("请输入要查询缴费状态的老人ID");
                                Integer olderIds= sc.nextInt();
                                List<PayMent> olderByStatus = rsco.findOlderByStatus(olderIds);
                                for (PayMent byStatus : olderByStatus) {
                                    if (byStatus.getPayStatus().equals(0)){
                                        System.out.println("老人Id:"+byStatus.getOlderId()+"---缴费状态:未缴费");
                                    }
                                    if (byStatus.getPayStatus().equals(1)){
                                        System.out.println("老人Id:"+byStatus.getOlderId()+"---缴费状态:已缴费");
                                    }
                                }
                                break;
                        }
                        break;
                    case 7:
                        System.out.println("------------护理人员信息管理------------");
                        System.out.println("1、护理人员信息查询");
                        System.out.println("2、护理人员信息修改");
                        System.out.println("3、护理人员信息新增");
                        System.out.println("4、护理人员信息删除");
                        System.out.println("请输入你的选择");
                        int key7 = sc.nextInt();
                        switch (key7) {
                            case 1:
                                //展示所有的护理人员信息
                                List<Nurse> allNurse = rsco.findAllNurse();
                                for (Nurse nurse : allNurse) {
                                    System.out.println(nurse);
                                }
                                break;
                            case 2:
                                //修改护理人员的信息
                                List<Nurse> allNurses = rsco.findAllNurse();
                                for (Nurse nurse : allNurses) {
                                    System.out.println(nurse);
                                }
                                System.out.println("请输入要修改信息的编号");
                                int nurseId = sc.nextInt();
                                Nurse nurse = rsco.existsNurseId(nurseId);
                                Nurse nurse1 = new Nurse();
                                if (nurse!=null){
                                    nurse1.setNurseId(nurseId);
                                    System.out.println("原护理人员名字为:"+nurse.getNurseName()+";修改后的为:");
                                    nurse1.setNurseName(sc.next());
                                    System.out.println("原护理人员性别为:"+nurse.getNurseGender()+";修改后的为:");
                                    nurse1.setNurseGender(sc.next());
                                    System.out.println("原护理人员薪资为:"+nurse.getNurseSalary()+";修改后的为:");
                                    nurse1.setNurseSalary(sc.nextDouble());
                                    System.out.println("原护理人员的等级为:"+nurse.getGrade());
                                    System.out.println("0----高级");
                                    System.out.println("1----中级");
                                    System.out.println("2----普通");
                                    System.out.println("请输入修改后的等级编号");
                                    nurse1.setGrade(sc.nextInt());
                                    Boolean aBoolean = rsco.updateNurse(nurse1);
                                    if (aBoolean){
                                        System.out.println("修改成功");
                                    }else {
                                        System.out.println("修改失败");
                                    }
                                }else {
                                    System.out.println("此医护人员不存在");
                                }
                                break;
                            case 3:
                                //添加一名护理人员的信息
                                Nurse nurse2 = new Nurse();
                                System.out.println("请输入新添加护理人的名字");
                                nurse2.setNurseName(sc.next());
                                System.out.println("请输入新添加护理人的性别");
                                nurse2.setNurseGender(sc.next());
                                System.out.println("请输入新添加护理人的薪资");
                                nurse2.setNurseSalary(sc.nextDouble());
                                System.out.println("请输入新添加护理人的等级编号");
                                System.out.println("0----高级");
                                System.out.println("1----中级");
                                System.out.println("2----普通");
                                nurse2.setGrade(sc.nextInt());
                                boolean b = rsco.addNurse(nurse2);
                                System.out.println(b?"添加成功":"添加失败");
                                break;
                            case 4:
                                //删除护理人员信息
                                List<Nurse> allNurses1 = rsco.findAllNurse();
                                for (Nurse nurse3 : allNurses1) {
                                    System.out.println(nurse3);
                                }
                                System.out.println("请输入要删除信息的编号");
                                Integer nursesId= sc.nextInt();
                                boolean b1 = rsco.deleteNurse(nursesId);
                                System.out.println(b1?"删除成功":"删除失败");
                                break;
                        }
                        break;
                    case 8:
                        System.out.println("1、外出报备");
                        System.out.println("2、查看外出信息");
                        System.out.println("3、外出归来修改报备状态");
                        System.out.println("请输入您的选择:");
                        Integer key8=sc.nextInt();
                        switch (key8){
                            case 1:
                                Outing outing81 = new Outing();
                                SimpleDateFormat sdf81 = new SimpleDateFormat("yyyy-MM-dd");
                                System.out.println("请输入外出事由");
                                outing81.setOutingReason(sc.next());
                                List<Older> all81 = rsco.findAll();
                                System.out.println("请选择外出老人编号");
                                for (Older older81 : all81) {
                                    System.out.println(older81.getOlderName()+"编号为："+older81.getOlderId());
                                }
                                outing81.setOlderId(sc.nextInt());
                                System.out.println("请输入外出时间");
                                String outingDate81=sc.next();
                                Date addOutingDate=null;
                                try {
                                    addOutingDate = sdf81.parse(outingDate81);
                                } catch (ParseException e) {
                                    e.printStackTrace();
                                }
                                outing81.setOutingDate(addOutingDate);
                                System.out.println("请输入外出状态：（0 1 2）");
                                outing81.setOutingStatus(sc.nextInt());
                                Boolean addOuting = rsco.addOuting(outing81);
                                System.out.println(addOuting?"添加成功":"添加失败");
                                break;
                            case 2:
                                List<Outing> showAllOuting = rsco.showAllOuting();
                                for (Outing outing82 : showAllOuting) {
                                    System.out.println(outing82);
                                }
                                break;
                            case 3:
                                Outing o83 = new Outing();
                                System.out.println("请输入外出报备ID");
                                Integer outingId83=sc.nextInt();
                                Outing outing83 = rsco.existsOutingId(outingId83);
                                if (outing83.getOutingId()!=null){
                                    o83.setOutingId(outingId83);
                                    System.out.println("原外出状态为："+outing83.getOutingStatus()+"请更新状态");
                                    o83.setOutingStatus(sc.nextInt());
                                }
                                Boolean updateOut83 = rsco.updateOuting(o83);
                                if (updateOut83!=null){
                                    System.out.println("修改成功");
                                }else {
                                    System.out.println("修改失败");
                                }
                                break;
                            default:
                                System.out.println("暂无此选择");
                                break;
                        }
                        break;


                }
                System.out.println("是否继续?Y/N");
                String next = sc.next();
                if (next.equalsIgnoreCase("Y")){
                    flag=true;
                }
                if (next.equalsIgnoreCase("N")){
                    System.exit(0);
                }
            }
        }else {
            System.out.println("用户名或密码输入错误！");
        }
    }
}
